package br.ufmg.dees.insane.ui.rich.prep.view;

import java.awt.Point;

import br.ufmg.dees.insane.commons.view.DrawingArea;
import br.ufmg.dees.insane.model.geo.halfEdgeDataStructure.Edge;
import br.ufmg.dees.insane.model.geo.halfEdgeDataStructure.Vertex;
import br.ufmg.dees.insane.ui.rich.prep.controller.PrepControllerHE;
import br.ufmg.dees.insane.util.IMatrix;
import br.ufmg.dees.insane.util.IPoint3d;

public class InquiryView {
	
//  ****************************************************************************	
	
	/** Returns a string with the vertex coordinates. */
	public static String getCoordsStr(Vertex v)
	{
		String strP3d = "( " + v.getCoords().x + " , "
      		  + v.getCoords().y + " , " + v.getCoords().z + " )";
		return strP3d;
	}
	
//  ****************************************************************************	
	
	/** Returns a string with the edge's vertex coordinates. */
	public static String getEdgeInfo(Edge edge)
	{
		String vS, vF, strEdge;
		vS = InquiryView.getCoordsStr(edge.getVStart());
		vF = InquiryView.getCoordsStr(edge.getVEnd());
		strEdge = " [ vi: " + vS + "  vf: " + vF + " ] ";
		return strEdge;
	}	
	
	
//  ****************************************************************************
	
	/** Transform a point 3d with the current transformation and returns 
	  * this point in the view.
	  */
	public static Point getPointTransformed(InterfacePrep intFrame, IPoint3d p3d)
	{
    	double x, y;
		PrepControllerHE controller = (PrepControllerHE)intFrame.getView().getController();
		DrawingArea da = intFrame.getView().getDrawingArea();
		IMatrix matPt = new IMatrix(1,4);
		IMatrix matTransf = controller.getCurrentTransform().getMatrix();
        matPt.setElement(0,0,p3d.x);
        matPt.setElement(0,1,p3d.y);
        matPt.setElement(0,2,p3d.z);
        matPt.setElement(0,3,1);
        matPt.mul(matTransf);  
        x = matPt.getElement(0,0);
        y = matPt.getElement(0,1);
        return da.getViewPoint(x,y); 
	}

//  ****************************************************************************	
}// end of the class
